<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>21.28. ipaddress — IPv4/IPv6 manipulation library &mdash; Python 3.4.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.4.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.4.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.4.3 documentation" href="../index.html" />
    <link rel="up" title="21. Internet Protocols and Support" href="internet.html" />
    <link rel="next" title="22. Multimedia Services" href="mm.html" />
    <link rel="prev" title="21.27. xmlrpc.server — Basic XML-RPC servers" href="xmlrpc.server.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
    
 

  </head>
  <body>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="mm.html" title="22. Multimedia Services"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="xmlrpc.server.html" title="21.27. xmlrpc.server — Basic XML-RPC servers"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="internet.html" accesskey="U">21. Internet Protocols and Support</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-ipaddress">
<span id="ipaddress-ipv4-ipv6-manipulation-library"></span><h1>21.28. <a class="reference internal" href="#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><tt class="xref py py-mod docutils literal"><span class="pre">ipaddress</span></tt></a> &#8212; IPv4/IPv6 manipulation library<a class="headerlink" href="#module-ipaddress" title="Permalink to this headline">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.4/Lib/ipaddress.py">Lib/ipaddress.py</a></p>
<hr class="docutils" />
<p><a class="reference internal" href="#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><tt class="xref py py-mod docutils literal"><span class="pre">ipaddress</span></tt></a> provides the capabilities to create, manipulate and
operate on IPv4 and IPv6 addresses and networks.</p>
<p>The functions and classes in this module make it straightforward to handle
various tasks related to IP addresses, including checking whether or not two
hosts are on the same subnet, iterating over all hosts in a particular
subnet, checking whether or not a string represents a valid IP address or
network definition, and so on.</p>
<p>This is the full module API reference—for an overview and introduction, see
<a class="reference internal" href="../howto/ipaddress.html#ipaddress-howto"><em>An introduction to the ipaddress module</em></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
<div class="section" id="convenience-factory-functions">
<h2>21.28.1. Convenience factory functions<a class="headerlink" href="#convenience-factory-functions" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><tt class="xref py py-mod docutils literal"><span class="pre">ipaddress</span></tt></a> module provides factory functions to conveniently create
IP addresses, networks and interfaces:</p>
<dl class="function">
<dt id="ipaddress.ip_address">
<tt class="descclassname">ipaddress.</tt><tt class="descname">ip_address</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.ip_address" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an <a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a> or <a class="reference internal" href="#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Address</span></tt></a> object depending on
the IP address passed as argument.  Either IPv4 or IPv6 addresses may be
supplied; integers less than 2**32 will be considered to be IPv4 by default.
A <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised if <em>address</em> does not represent a valid IPv4
or IPv6 address.</p>
</dd></dl>

<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">ip_address</span><span class="p">(</span><span class="s">&#39;192.168.0.1&#39;</span><span class="p">)</span>
<span class="go">IPv4Address(&#39;192.168.0.1&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">ip_address</span><span class="p">(</span><span class="s">&#39;2001:db8::&#39;</span><span class="p">)</span>
<span class="go">IPv6Address(&#39;2001:db8::&#39;)</span>
</pre></div>
</div>
<dl class="function">
<dt id="ipaddress.ip_network">
<tt class="descclassname">ipaddress.</tt><tt class="descname">ip_network</tt><big>(</big><em>address</em>, <em>strict=True</em><big>)</big><a class="headerlink" href="#ipaddress.ip_network" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a> or <a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a> object depending on
the IP address passed as argument.  <em>address</em> is a string or integer
representing the IP network.  Either IPv4 or IPv6 networks may be supplied;
integers less than 2**32 will be considered to be IPv4 by default.  <em>strict</em>
is passed to <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a> or <a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a> constructor.  A
<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised if <em>address</em> does not represent a valid IPv4 or
IPv6 address, or if the network has host bits set.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.168.0.0/28&#39;</span><span class="p">)</span>
<span class="go">IPv4Network(&#39;192.168.0.0/28&#39;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="ipaddress.ip_interface">
<tt class="descclassname">ipaddress.</tt><tt class="descname">ip_interface</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.ip_interface" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an <a class="reference internal" href="#ipaddress.IPv4Interface" title="ipaddress.IPv4Interface"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Interface</span></tt></a> or <a class="reference internal" href="#ipaddress.IPv6Interface" title="ipaddress.IPv6Interface"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Interface</span></tt></a> object depending
on the IP address passed as argument.  <em>address</em> is a string or integer
representing the IP address.  Either IPv4 or IPv6 addresses may be supplied;
integers less than 2**32 will be considered to be IPv4 by default.  A
<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised if <em>address</em> does not represent a valid IPv4 or
IPv6 address.</p>
</dd></dl>

<p>One downside of these convenience functions is that the need to handle both
IPv4 and IPv6 formats means that error messages provide minimal
information on the precise error, as the functions don&#8217;t know whether the
IPv4 or IPv6 format was intended. More detailed error reporting can be
obtained by calling the appropriate version specific class constructors
directly.</p>
</div>
<div class="section" id="ip-addresses">
<h2>21.28.2. IP Addresses<a class="headerlink" href="#ip-addresses" title="Permalink to this headline">¶</a></h2>
<div class="section" id="address-objects">
<h3>21.28.2.1. Address objects<a class="headerlink" href="#address-objects" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a> and <a class="reference internal" href="#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Address</span></tt></a> objects share a lot of common
attributes.  Some attributes that are only meaningful for IPv6 addresses are
also implemented by <a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a> objects, in order to make it easier to
write code that handles both IP versions correctly.</p>
<dl class="class">
<dt id="ipaddress.IPv4Address">
<em class="property">class </em><tt class="descclassname">ipaddress.</tt><tt class="descname">IPv4Address</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Address" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an IPv4 address.  An <a class="reference internal" href="#ipaddress.AddressValueError" title="ipaddress.AddressValueError"><tt class="xref py py-exc docutils literal"><span class="pre">AddressValueError</span></tt></a> is raised if
<em>address</em> is not a valid IPv4 address.</p>
<p>The following constitutes a valid IPv4 address:</p>
<ol class="arabic simple">
<li>A string in decimal-dot notation, consisting of four decimal integers in
the inclusive range 0-255, separated by dots (e.g. <tt class="docutils literal"><span class="pre">192.168.0.1</span></tt>). Each
integer represents an octet (byte) in the address. Leading zeroes are
tolerated only for values less than 8 (as there is no ambiguity
between the decimal and octal interpretations of such strings).</li>
<li>An integer that fits into 32 bits.</li>
<li>An integer packed into a <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> object of length 4 (most
significant octet first).</li>
</ol>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.168.0.1&#39;</span><span class="p">)</span>
<span class="go">IPv4Address(&#39;192.168.0.1&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="mi">3232235521</span><span class="p">)</span>
<span class="go">IPv4Address(&#39;192.168.0.1&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="n">b</span><span class="s">&#39;</span><span class="se">\xC0\xA8\x00\x01</span><span class="s">&#39;</span><span class="p">)</span>
<span class="go">IPv4Address(&#39;192.168.0.1&#39;)</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="ipaddress.IPv4Address.version">
<tt class="descname">version</tt><a class="headerlink" href="#ipaddress.IPv4Address.version" title="Permalink to this definition">¶</a></dt>
<dd><p>The appropriate version number: <tt class="docutils literal"><span class="pre">4</span></tt> for IPv4, <tt class="docutils literal"><span class="pre">6</span></tt> for IPv6.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.max_prefixlen">
<tt class="descname">max_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv4Address.max_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of bits in the address representation for this
version: <tt class="docutils literal"><span class="pre">32</span></tt> for IPv4, <tt class="docutils literal"><span class="pre">128</span></tt> for IPv6.</p>
<p>The prefix defines the number of leading bits in an  address that
are compared to determine whether or not an address is part of a
network.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.compressed">
<tt class="descname">compressed</tt><a class="headerlink" href="#ipaddress.IPv4Address.compressed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.exploded">
<tt class="descname">exploded</tt><a class="headerlink" href="#ipaddress.IPv4Address.exploded" title="Permalink to this definition">¶</a></dt>
<dd><p>The string representation in dotted decimal notation. Leading zeroes
are never included in the representation.</p>
<p>As IPv4 does not define a shorthand notation for addresses with octets
set to zero, these two attributes are always the same as <tt class="docutils literal"><span class="pre">str(addr)</span></tt>
for IPv4 addresses. Exposing these attributes makes it easier to
write display code that can handle both IPv4 and IPv6 addresses.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.packed">
<tt class="descname">packed</tt><a class="headerlink" href="#ipaddress.IPv4Address.packed" title="Permalink to this definition">¶</a></dt>
<dd><p>The binary representation of this address - a <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> object of
the appropriate length (most significant octet first). This is 4 bytes
for IPv4 and 16 bytes for IPv6.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_multicast">
<tt class="descname">is_multicast</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_multicast" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is reserved for multicast use.  See
<span class="target" id="index-0"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc3171.html"><strong>RFC 3171</strong></a> (for IPv4) or <span class="target" id="index-1"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2373.html"><strong>RFC 2373</strong></a> (for IPv6).</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_private">
<tt class="descname">is_private</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_private" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is allocated for private networks.  See
<a class="reference external" href="http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml">iana-ipv4-special-registry</a> (for IPv4) or <a class="reference external" href="http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml">iana-ipv6-special-registry</a>
(for IPv6).</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_global">
<tt class="descname">is_global</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_global" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is allocated for public networks.  See
<a class="reference external" href="http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml">iana-ipv4-special-registry</a> (for IPv4) or <a class="reference external" href="http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml">iana-ipv6-special-registry</a>
(for IPv6).</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.4.</span></p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_unspecified">
<tt class="descname">is_unspecified</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_unspecified" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is unspecified.  See <span class="target" id="index-2"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc5735.html"><strong>RFC 5735</strong></a> (for IPv4)
or <span class="target" id="index-3"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2373.html"><strong>RFC 2373</strong></a> (for IPv6).</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_reserved">
<tt class="descname">is_reserved</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_reserved" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is otherwise IETF reserved.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_loopback">
<tt class="descname">is_loopback</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_loopback" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if this is a loopback address.  See <span class="target" id="index-4"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc3330.html"><strong>RFC 3330</strong></a> (for IPv4)
or <span class="target" id="index-5"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2373.html"><strong>RFC 2373</strong></a> (for IPv6).</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Address.is_link_local">
<tt class="descname">is_link_local</tt><a class="headerlink" href="#ipaddress.IPv4Address.is_link_local" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is reserved for link-local usage.  See
<span class="target" id="index-6"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc3927.html"><strong>RFC 3927</strong></a>.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="ipaddress.IPv6Address">
<em class="property">class </em><tt class="descclassname">ipaddress.</tt><tt class="descname">IPv6Address</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Address" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an IPv6 address.  An <a class="reference internal" href="#ipaddress.AddressValueError" title="ipaddress.AddressValueError"><tt class="xref py py-exc docutils literal"><span class="pre">AddressValueError</span></tt></a> is raised if
<em>address</em> is not a valid IPv6 address.</p>
<p>The following constitutes a valid IPv6 address:</p>
<ol class="arabic simple">
<li>A string consisting of eight groups of four hexadecimal digits, each
group representing 16 bits.  The groups are separated by colons.
This describes an <em>exploded</em> (longhand) notation.  The string can
also be <em>compressed</em> (shorthand notation) by various means.  See
<span class="target" id="index-7"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc4291.html"><strong>RFC 4291</strong></a> for details.  For example,
<tt class="docutils literal"><span class="pre">&quot;0000:0000:0000:0000:0000:0abc:0007:0def&quot;</span></tt> can be compressed to
<tt class="docutils literal"><span class="pre">&quot;::abc:7:def&quot;</span></tt>.</li>
<li>An integer that fits into 128 bits.</li>
<li>An integer packed into a <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> object of length 16, big-endian.</li>
</ol>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv6Address</span><span class="p">(</span><span class="s">&#39;2001:db8::1000&#39;</span><span class="p">)</span>
<span class="go">IPv6Address(&#39;2001:db8::1000&#39;)</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="ipaddress.IPv6Address.compressed">
<tt class="descname">compressed</tt><a class="headerlink" href="#ipaddress.IPv6Address.compressed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The short form of the address representation, with leading zeroes in
groups omitted and the longest sequence of groups consisting entirely of
zeroes collapsed to a single empty group.</p>
<p>This is also the value returned by <tt class="docutils literal"><span class="pre">str(addr)</span></tt> for IPv6 addresses.</p>
<dl class="attribute">
<dt id="ipaddress.IPv6Address.exploded">
<tt class="descname">exploded</tt><a class="headerlink" href="#ipaddress.IPv6Address.exploded" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The long form of the address representation, with all leading zeroes and
groups consisting entirely of zeroes included.</p>
<p>For the following attributes, see the corresponding documention of the
<a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a> class:</p>
<dl class="attribute">
<dt id="ipaddress.IPv6Address.packed">
<tt class="descname">packed</tt><a class="headerlink" href="#ipaddress.IPv6Address.packed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.version">
<tt class="descname">version</tt><a class="headerlink" href="#ipaddress.IPv6Address.version" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.max_prefixlen">
<tt class="descname">max_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv6Address.max_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_multicast">
<tt class="descname">is_multicast</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_multicast" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_private">
<tt class="descname">is_private</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_private" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_global">
<tt class="descname">is_global</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_global" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_unspecified">
<tt class="descname">is_unspecified</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_unspecified" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_reserved">
<tt class="descname">is_reserved</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_reserved" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_loopback">
<tt class="descname">is_loopback</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_loopback" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_link_local">
<tt class="descname">is_link_local</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_link_local" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.4: </span>is_global</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.is_site_local">
<tt class="descname">is_site_local</tt><a class="headerlink" href="#ipaddress.IPv6Address.is_site_local" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the address is reserved for site-local usage.  Note that
the site-local address space has been deprecated by <span class="target" id="index-8"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc3879.html"><strong>RFC 3879</strong></a>. Use
<a class="reference internal" href="#ipaddress.IPv4Address.is_private" title="ipaddress.IPv4Address.is_private"><tt class="xref py py-attr docutils literal"><span class="pre">is_private</span></tt></a> to test if this address is in the
space of unique local addresses as defined by <span class="target" id="index-9"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc4193.html"><strong>RFC 4193</strong></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.ipv4_mapped">
<tt class="descname">ipv4_mapped</tt><a class="headerlink" href="#ipaddress.IPv6Address.ipv4_mapped" title="Permalink to this definition">¶</a></dt>
<dd><p>For addresses that appear to be IPv4 mapped addresses (starting with
<tt class="docutils literal"><span class="pre">::FFFF/96</span></tt>), this property will report the embedded IPv4 address.
For any other address, this property will be <tt class="docutils literal"><span class="pre">None</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.sixtofour">
<tt class="descname">sixtofour</tt><a class="headerlink" href="#ipaddress.IPv6Address.sixtofour" title="Permalink to this definition">¶</a></dt>
<dd><p>For addresses that appear to be 6to4 addresses  (starting with
<tt class="docutils literal"><span class="pre">2002::/16</span></tt>) as defined by <span class="target" id="index-10"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc3056.html"><strong>RFC 3056</strong></a>, this property will report
the embedded IPv4 address.  For any other address, this property will
be <tt class="docutils literal"><span class="pre">None</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Address.teredo">
<tt class="descname">teredo</tt><a class="headerlink" href="#ipaddress.IPv6Address.teredo" title="Permalink to this definition">¶</a></dt>
<dd><p>For addresses that appear to be Teredo addresses (starting with
<tt class="docutils literal"><span class="pre">2001::/32</span></tt>) as defined by <span class="target" id="index-11"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc4380.html"><strong>RFC 4380</strong></a>, this property will report
the embedded <tt class="docutils literal"><span class="pre">(server,</span> <span class="pre">client)</span></tt> IP address pair.  For any other
address, this property will be <tt class="docutils literal"><span class="pre">None</span></tt>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="conversion-to-strings-and-integers">
<h3>21.28.2.2. Conversion to Strings and Integers<a class="headerlink" href="#conversion-to-strings-and-integers" title="Permalink to this headline">¶</a></h3>
<p>To interoperate with networking interfaces such as the socket module,
addresses must be converted to strings or integers. This is handled using
the <a class="reference internal" href="stdtypes.html#str" title="str"><tt class="xref py py-func docutils literal"><span class="pre">str()</span></tt></a> and <a class="reference internal" href="functions.html#int" title="int"><tt class="xref py py-func docutils literal"><span class="pre">int()</span></tt></a> builtin functions:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.168.0.1&#39;</span><span class="p">))</span>
<span class="go">&#39;192.168.0.1&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">int</span><span class="p">(</span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.168.0.1&#39;</span><span class="p">))</span>
<span class="go">3232235521</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv6Address</span><span class="p">(</span><span class="s">&#39;::1&#39;</span><span class="p">))</span>
<span class="go">&#39;::1&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">int</span><span class="p">(</span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv6Address</span><span class="p">(</span><span class="s">&#39;::1&#39;</span><span class="p">))</span>
<span class="go">1</span>
</pre></div>
</div>
</div>
<div class="section" id="operators">
<h3>21.28.2.3. Operators<a class="headerlink" href="#operators" title="Permalink to this headline">¶</a></h3>
<p>Address objects support some operators.  Unless stated otherwise, operators can
only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with
IPv6).</p>
<div class="section" id="comparison-operators">
<h4>21.28.2.3.1. Comparison operators<a class="headerlink" href="#comparison-operators" title="Permalink to this headline">¶</a></h4>
<p>Address objects can be compared with the usual set of comparison operators.  Some
examples:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.2&#39;</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.1&#39;</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.2&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.1&#39;</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.2&#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.1&#39;</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</div>
<div class="section" id="arithmetic-operators">
<h4>21.28.2.3.2. Arithmetic operators<a class="headerlink" href="#arithmetic-operators" title="Permalink to this headline">¶</a></h4>
<p>Integers can be added to or subtracted from address objects.  Some examples:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.2&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span>
<span class="go">IPv4Address(&#39;127.0.0.5&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;127.0.0.2&#39;</span><span class="p">)</span> <span class="o">-</span> <span class="mi">3</span>
<span class="go">IPv4Address(&#39;126.255.255.255&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;255.255.255.255&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
<span class="gt">Traceback (most recent call last):</span>
  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
<span class="gr">ipaddress.AddressValueError</span>: <span class="n">4294967296 (&gt;= 2**32) is not permitted as an IPv4 address</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="ip-network-definitions">
<h2>21.28.3. IP Network definitions<a class="headerlink" href="#ip-network-definitions" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a> and <a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a> objects provide a mechanism
for defining and inspecting IP network definitions.  A network definition
consists of a <em>mask</em> and a <em>network address</em>, and as such defines a range of
IP addresses that equal the network address when masked (binary AND) with the
mask.  For example, a network definition with the mask <tt class="docutils literal"><span class="pre">255.255.255.0</span></tt> and
the network address <tt class="docutils literal"><span class="pre">192.168.1.0</span></tt> consists of IP addresses in the inclusive
range <tt class="docutils literal"><span class="pre">192.168.1.0</span></tt> to <tt class="docutils literal"><span class="pre">192.168.1.255</span></tt>.</p>
<div class="section" id="prefix-net-mask-and-host-mask">
<h3>21.28.3.1. Prefix, net mask and host mask<a class="headerlink" href="#prefix-net-mask-and-host-mask" title="Permalink to this headline">¶</a></h3>
<p>There are several equivalent ways to specify IP network masks.  A <em>prefix</em>
<tt class="docutils literal"><span class="pre">/&lt;nbits&gt;</span></tt> is a notation that denotes how many high-order bits are set in
the network mask.  A <em>net mask</em> is an IP address with some number of
high-order bits set.  Thus the prefix <tt class="docutils literal"><span class="pre">/24</span></tt> is equivalent to the net mask
<tt class="docutils literal"><span class="pre">255.255.255.0</span></tt> in IPv4, or <tt class="docutils literal"><span class="pre">ffff:ff00::</span></tt> in IPv6.  In addition, a
<em>host mask</em> is the logical inverse of a <em>net mask</em>, and is sometimes used
(for example in Cisco access control lists) to denote a network mask.  The
host mask equivalent to <tt class="docutils literal"><span class="pre">/24</span></tt> in IPv4 is <tt class="docutils literal"><span class="pre">0.0.0.255</span></tt>.</p>
</div>
<div class="section" id="network-objects">
<h3>21.28.3.2. Network objects<a class="headerlink" href="#network-objects" title="Permalink to this headline">¶</a></h3>
<p>All attributes implemented by address objects are implemented by network
objects as well.  In addition, network objects implement additional attributes.
All of these are common between <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a> and <a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a>,
so to avoid duplication they are only documented for <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a>.</p>
<dl class="class">
<dt id="ipaddress.IPv4Network">
<em class="property">class </em><tt class="descclassname">ipaddress.</tt><tt class="descname">IPv4Network</tt><big>(</big><em>address</em>, <em>strict=True</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an IPv4 network definition.  <em>address</em> can be one of the following:</p>
<ol class="arabic">
<li><p class="first">A string consisting of an IP address and an optional mask, separated by
a slash (<tt class="docutils literal"><span class="pre">/</span></tt>).  The IP address is the network address, and the mask
can be either a single number, which means it&#8217;s a <em>prefix</em>, or a string
representation of an IPv4 address.  If it&#8217;s the latter, the mask is
interpreted as a <em>net mask</em> if it starts with a non-zero field, or as
a <em>host mask</em> if it starts with a zero field.  If no mask is provided,
it&#8217;s considered to be <tt class="docutils literal"><span class="pre">/32</span></tt>.</p>
<p>For example, the following <em>address</em> specifications are equivalent:
<tt class="docutils literal"><span class="pre">192.168.1.0/24</span></tt>, <tt class="docutils literal"><span class="pre">192.168.1.0/255.255.255.0</span></tt> and
<tt class="docutils literal"><span class="pre">192.168.1.0/0.0.0.255</span></tt>.</p>
</li>
<li><p class="first">An integer that fits into 32 bits.  This is equivalent to a
single-address network, with the network address being <em>address</em> and
the mask being <tt class="docutils literal"><span class="pre">/32</span></tt>.</p>
</li>
<li><p class="first">An integer packed into a <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> object of length 4, big-endian.
The interpretation is similar to an integer <em>address</em>.</p>
</li>
</ol>
<p>An <a class="reference internal" href="#ipaddress.AddressValueError" title="ipaddress.AddressValueError"><tt class="xref py py-exc docutils literal"><span class="pre">AddressValueError</span></tt></a> is raised if <em>address</em> is not a valid IPv4
address.  A <a class="reference internal" href="#ipaddress.NetmaskValueError" title="ipaddress.NetmaskValueError"><tt class="xref py py-exc docutils literal"><span class="pre">NetmaskValueError</span></tt></a> is raised if the mask is not valid for
an IPv4 address.</p>
<p>If <em>strict</em> is <tt class="docutils literal"><span class="pre">True</span></tt> and host bits are set in the supplied address,
then <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  Otherwise, the host bits are masked out
to determine the appropriate network address.</p>
<p>Unless stated otherwise, all network methods accepting other network/address
objects will raise <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a> if the argument&#8217;s IP version is
incompatible to <tt class="docutils literal"><span class="pre">self</span></tt></p>
<dl class="attribute">
<dt id="ipaddress.IPv4Network.version">
<tt class="descname">version</tt><a class="headerlink" href="#ipaddress.IPv4Network.version" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.max_prefixlen">
<tt class="descname">max_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv4Network.max_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd><p>Refer to the corresponding attribute documentation in
<a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a></p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.is_multicast">
<tt class="descname">is_multicast</tt><a class="headerlink" href="#ipaddress.IPv4Network.is_multicast" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.is_private">
<tt class="descname">is_private</tt><a class="headerlink" href="#ipaddress.IPv4Network.is_private" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.is_unspecified">
<tt class="descname">is_unspecified</tt><a class="headerlink" href="#ipaddress.IPv4Network.is_unspecified" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.is_reserved">
<tt class="descname">is_reserved</tt><a class="headerlink" href="#ipaddress.IPv4Network.is_reserved" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.is_loopback">
<tt class="descname">is_loopback</tt><a class="headerlink" href="#ipaddress.IPv4Network.is_loopback" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.is_link_local">
<tt class="descname">is_link_local</tt><a class="headerlink" href="#ipaddress.IPv4Network.is_link_local" title="Permalink to this definition">¶</a></dt>
<dd><p>These attributes are true for the network as a whole if they are true
for both the network address and the broadcast address</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.network_address">
<tt class="descname">network_address</tt><a class="headerlink" href="#ipaddress.IPv4Network.network_address" title="Permalink to this definition">¶</a></dt>
<dd><p>The network address for the network. The network address and the
prefix length together uniquely define a network.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.broadcast_address">
<tt class="descname">broadcast_address</tt><a class="headerlink" href="#ipaddress.IPv4Network.broadcast_address" title="Permalink to this definition">¶</a></dt>
<dd><p>The broadcast address for the network. Packets sent to the broadcast
address should be received by every host on the network.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.hostmask">
<tt class="descname">hostmask</tt><a class="headerlink" href="#ipaddress.IPv4Network.hostmask" title="Permalink to this definition">¶</a></dt>
<dd><p>The host mask, as a string.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.with_prefixlen">
<tt class="descname">with_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv4Network.with_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.compressed">
<tt class="descname">compressed</tt><a class="headerlink" href="#ipaddress.IPv4Network.compressed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.exploded">
<tt class="descname">exploded</tt><a class="headerlink" href="#ipaddress.IPv4Network.exploded" title="Permalink to this definition">¶</a></dt>
<dd><p>A string representation of the network, with the mask in prefix
notation.</p>
<p><tt class="docutils literal"><span class="pre">with_prefixlen</span></tt> and <tt class="docutils literal"><span class="pre">compressed</span></tt> are always the same as
<tt class="docutils literal"><span class="pre">str(network)</span></tt>.
<tt class="docutils literal"><span class="pre">exploded</span></tt> uses the exploded form the network address.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.with_netmask">
<tt class="descname">with_netmask</tt><a class="headerlink" href="#ipaddress.IPv4Network.with_netmask" title="Permalink to this definition">¶</a></dt>
<dd><p>A string representation of the network, with the mask in net mask
notation.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.with_hostmask">
<tt class="descname">with_hostmask</tt><a class="headerlink" href="#ipaddress.IPv4Network.with_hostmask" title="Permalink to this definition">¶</a></dt>
<dd><p>A string representation of the network, with the mask in host mask
notation.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.num_addresses">
<tt class="descname">num_addresses</tt><a class="headerlink" href="#ipaddress.IPv4Network.num_addresses" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of addresses in the network.</p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Network.prefixlen">
<tt class="descname">prefixlen</tt><a class="headerlink" href="#ipaddress.IPv4Network.prefixlen" title="Permalink to this definition">¶</a></dt>
<dd><p>Length of the network prefix, in bits.</p>
</dd></dl>

<dl class="method">
<dt id="ipaddress.IPv4Network.hosts">
<tt class="descname">hosts</tt><big>(</big><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network.hosts" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an iterator over the usable hosts in the network.  The usable
hosts are all the IP addresses that belong to the network, except the
network address itself and the network broadcast address.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/29&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">hosts</span><span class="p">())</span>  
<span class="go">[IPv4Address(&#39;192.0.2.1&#39;), IPv4Address(&#39;192.0.2.2&#39;),</span>
<span class="go"> IPv4Address(&#39;192.0.2.3&#39;), IPv4Address(&#39;192.0.2.4&#39;),</span>
<span class="go"> IPv4Address(&#39;192.0.2.5&#39;), IPv4Address(&#39;192.0.2.6&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="ipaddress.IPv4Network.overlaps">
<tt class="descname">overlaps</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network.overlaps" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if this network is partly or wholly contained in <em>other</em> or
<em>other</em> is wholly contained in this network.</p>
</dd></dl>

<dl class="method">
<dt id="ipaddress.IPv4Network.address_exclude">
<tt class="descname">address_exclude</tt><big>(</big><em>network</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network.address_exclude" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the network definitions resulting from removing the given
<em>network</em> from this one.  Returns an iterator of network objects.
Raises <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> if <em>network</em> is not completely contained in
this network.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">n1</span> <span class="o">=</span> <span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/28&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n2</span> <span class="o">=</span> <span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.1/32&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">n1</span><span class="o">.</span><span class="n">address_exclude</span><span class="p">(</span><span class="n">n2</span><span class="p">))</span>  
<span class="go">[IPv4Network(&#39;192.0.2.8/29&#39;), IPv4Network(&#39;192.0.2.4/30&#39;),</span>
<span class="go"> IPv4Network(&#39;192.0.2.2/31&#39;), IPv4Network(&#39;192.0.2.0/32&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="ipaddress.IPv4Network.subnets">
<tt class="descname">subnets</tt><big>(</big><em>prefixlen_diff=1</em>, <em>new_prefix=None</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network.subnets" title="Permalink to this definition">¶</a></dt>
<dd><p>The subnets that join to make the current network definition, depending
on the argument values.  <em>prefixlen_diff</em> is the amount our prefix
length should be increased by.  <em>new_prefix</em> is the desired new
prefix of the subnets; it must be larger than our prefix.  One and
only one of <em>prefixlen_diff</em> and <em>new_prefix</em> must be set.  Returns an
iterator of network objects.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">subnets</span><span class="p">())</span>
<span class="go">[IPv4Network(&#39;192.0.2.0/25&#39;), IPv4Network(&#39;192.0.2.128/25&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">subnets</span><span class="p">(</span><span class="n">prefixlen_diff</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span>  
<span class="go">[IPv4Network(&#39;192.0.2.0/26&#39;), IPv4Network(&#39;192.0.2.64/26&#39;),</span>
<span class="go"> IPv4Network(&#39;192.0.2.128/26&#39;), IPv4Network(&#39;192.0.2.192/26&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">subnets</span><span class="p">(</span><span class="n">new_prefix</span><span class="o">=</span><span class="mi">26</span><span class="p">))</span>  
<span class="go">[IPv4Network(&#39;192.0.2.0/26&#39;), IPv4Network(&#39;192.0.2.64/26&#39;),</span>
<span class="go"> IPv4Network(&#39;192.0.2.128/26&#39;), IPv4Network(&#39;192.0.2.192/26&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">subnets</span><span class="p">(</span><span class="n">new_prefix</span><span class="o">=</span><span class="mi">23</span><span class="p">))</span>
<span class="gt">Traceback (most recent call last):</span>
  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;new prefix must be longer&#39;</span><span class="p">)</span>
<span class="gr">ValueError</span>: <span class="n">new prefix must be longer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">subnets</span><span class="p">(</span><span class="n">new_prefix</span><span class="o">=</span><span class="mi">25</span><span class="p">))</span>
<span class="go">[IPv4Network(&#39;192.0.2.0/25&#39;), IPv4Network(&#39;192.0.2.128/25&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="ipaddress.IPv4Network.supernet">
<tt class="descname">supernet</tt><big>(</big><em>prefixlen_diff=1</em>, <em>new_prefix=None</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network.supernet" title="Permalink to this definition">¶</a></dt>
<dd><p>The supernet containing this network definition, depending on the
argument values.  <em>prefixlen_diff</em> is the amount our prefix length
should be decreased by.  <em>new_prefix</em> is the desired new prefix of
the supernet; it must be smaller than our prefix.  One and only one
of <em>prefixlen_diff</em> and <em>new_prefix</em> must be set.  Returns a single
network object.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">supernet</span><span class="p">()</span>
<span class="go">IPv4Network(&#39;192.0.2.0/23&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">supernet</span><span class="p">(</span><span class="n">prefixlen_diff</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="go">IPv4Network(&#39;192.0.0.0/22&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">supernet</span><span class="p">(</span><span class="n">new_prefix</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
<span class="go">IPv4Network(&#39;192.0.0.0/20&#39;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="ipaddress.IPv4Network.compare_networks">
<tt class="descname">compare_networks</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Network.compare_networks" title="Permalink to this definition">¶</a></dt>
<dd><p>Compare this network to <em>other</em>.  In this comparison only the network
addresses are considered; host bits aren&#8217;t.  Returns either <tt class="docutils literal"><span class="pre">-1</span></tt>,
<tt class="docutils literal"><span class="pre">0</span></tt> or <tt class="docutils literal"><span class="pre">1</span></tt>.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.1/32&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">compare_networks</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.2/32&#39;</span><span class="p">))</span>
<span class="go">-1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.1/32&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">compare_networks</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/32&#39;</span><span class="p">))</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.1/32&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">compare_networks</span><span class="p">(</span><span class="n">ip_network</span><span class="p">(</span><span class="s">&#39;192.0.2.1/32&#39;</span><span class="p">))</span>
<span class="go">0</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="ipaddress.IPv6Network">
<em class="property">class </em><tt class="descclassname">ipaddress.</tt><tt class="descname">IPv6Network</tt><big>(</big><em>address</em>, <em>strict=True</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an IPv6 network definition.  <em>address</em> can be one of the following:</p>
<ol class="arabic">
<li><p class="first">A string consisting of an IP address and an optional mask, separated by
a slash (<tt class="docutils literal"><span class="pre">/</span></tt>).  The IP address is the network address, and the mask
can be either a single number, which means it&#8217;s a <em>prefix</em>, or a string
representation of an IPv6 address.  If it&#8217;s the latter, the mask is
interpreted as a <em>net mask</em>.  If no mask is provided, it&#8217;s considered to
be <tt class="docutils literal"><span class="pre">/128</span></tt>.</p>
<p>For example, the following <em>address</em> specifications are equivalent:
<tt class="docutils literal"><span class="pre">2001:db00::0/24</span></tt> and <tt class="docutils literal"><span class="pre">2001:db00::0/ffff:ff00::</span></tt>.</p>
</li>
<li><p class="first">An integer that fits into 128 bits.  This is equivalent to a
single-address network, with the network address being <em>address</em> and
the mask being <tt class="docutils literal"><span class="pre">/128</span></tt>.</p>
</li>
<li><p class="first">An integer packed into a <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> object of length 16, big-endian.
The interpretation is similar to an integer <em>address</em>.</p>
</li>
</ol>
<p>An <a class="reference internal" href="#ipaddress.AddressValueError" title="ipaddress.AddressValueError"><tt class="xref py py-exc docutils literal"><span class="pre">AddressValueError</span></tt></a> is raised if <em>address</em> is not a valid IPv6
address.  A <a class="reference internal" href="#ipaddress.NetmaskValueError" title="ipaddress.NetmaskValueError"><tt class="xref py py-exc docutils literal"><span class="pre">NetmaskValueError</span></tt></a> is raised if the mask is not valid for
an IPv6 address.</p>
<p>If <em>strict</em> is <tt class="docutils literal"><span class="pre">True</span></tt> and host bits are set in the supplied address,
then <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  Otherwise, the host bits are masked out
to determine the appropriate network address.</p>
<dl class="attribute">
<dt id="ipaddress.IPv6Network.version">
<tt class="descname">version</tt><a class="headerlink" href="#ipaddress.IPv6Network.version" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.max_prefixlen">
<tt class="descname">max_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv6Network.max_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_multicast">
<tt class="descname">is_multicast</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_multicast" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_private">
<tt class="descname">is_private</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_private" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_unspecified">
<tt class="descname">is_unspecified</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_unspecified" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_reserved">
<tt class="descname">is_reserved</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_reserved" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_loopback">
<tt class="descname">is_loopback</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_loopback" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_link_local">
<tt class="descname">is_link_local</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_link_local" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.network_address">
<tt class="descname">network_address</tt><a class="headerlink" href="#ipaddress.IPv6Network.network_address" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.broadcast_address">
<tt class="descname">broadcast_address</tt><a class="headerlink" href="#ipaddress.IPv6Network.broadcast_address" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.hostmask">
<tt class="descname">hostmask</tt><a class="headerlink" href="#ipaddress.IPv6Network.hostmask" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.with_prefixlen">
<tt class="descname">with_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv6Network.with_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.compressed">
<tt class="descname">compressed</tt><a class="headerlink" href="#ipaddress.IPv6Network.compressed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.exploded">
<tt class="descname">exploded</tt><a class="headerlink" href="#ipaddress.IPv6Network.exploded" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.with_netmask">
<tt class="descname">with_netmask</tt><a class="headerlink" href="#ipaddress.IPv6Network.with_netmask" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.with_hostmask">
<tt class="descname">with_hostmask</tt><a class="headerlink" href="#ipaddress.IPv6Network.with_hostmask" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.num_addresses">
<tt class="descname">num_addresses</tt><a class="headerlink" href="#ipaddress.IPv6Network.num_addresses" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.prefixlen">
<tt class="descname">prefixlen</tt><a class="headerlink" href="#ipaddress.IPv6Network.prefixlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="ipaddress.IPv6Network.hosts">
<tt class="descname">hosts</tt><big>(</big><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network.hosts" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="ipaddress.IPv6Network.overlaps">
<tt class="descname">overlaps</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network.overlaps" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="ipaddress.IPv6Network.address_exclude">
<tt class="descname">address_exclude</tt><big>(</big><em>network</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network.address_exclude" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="ipaddress.IPv6Network.subnets">
<tt class="descname">subnets</tt><big>(</big><em>prefixlen_diff=1</em>, <em>new_prefix=None</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network.subnets" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="ipaddress.IPv6Network.supernet">
<tt class="descname">supernet</tt><big>(</big><em>prefixlen_diff=1</em>, <em>new_prefix=None</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network.supernet" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="ipaddress.IPv6Network.compare_networks">
<tt class="descname">compare_networks</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Network.compare_networks" title="Permalink to this definition">¶</a></dt>
<dd><p>Refer to the corresponding attribute documentation in
<a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a></p>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Network.is_site_local">
<tt class="descname">is_site_local</tt><a class="headerlink" href="#ipaddress.IPv6Network.is_site_local" title="Permalink to this definition">¶</a></dt>
<dd><p>These attribute is true for the network as a whole if it is true
for both the network address and the broadcast address</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="id1">
<h3>21.28.3.3. Operators<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>Network objects support some operators.  Unless stated otherwise, operators can
only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with
IPv6).</p>
<div class="section" id="logical-operators">
<h4>21.28.3.3.1. Logical operators<a class="headerlink" href="#logical-operators" title="Permalink to this headline">¶</a></h4>
<p>Network objects can be compared with the usual set of logical operators,
similarly to address objects.</p>
</div>
<div class="section" id="iteration">
<h4>21.28.3.3.2. Iteration<a class="headerlink" href="#iteration" title="Permalink to this headline">¶</a></h4>
<p>Network objects can be iterated to list all the addresses belonging to the
network.  For iteration, <em>all</em> hosts are returned, including unusable hosts
(for usable hosts, use the <a class="reference internal" href="#ipaddress.IPv4Network.hosts" title="ipaddress.IPv4Network.hosts"><tt class="xref py py-meth docutils literal"><span class="pre">hosts()</span></tt></a> method).  An
example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">addr</span> <span class="ow">in</span> <span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/28&#39;</span><span class="p">):</span>
<span class="gp">... </span>  <span class="n">addr</span>
<span class="gp">...</span>
<span class="go">IPv4Address(&#39;192.0.2.0&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.1&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.2&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.3&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.4&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.5&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.6&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.7&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.8&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.9&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.10&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.11&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.12&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.13&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.14&#39;)</span>
<span class="go">IPv4Address(&#39;192.0.2.15&#39;)</span>
</pre></div>
</div>
</div>
<div class="section" id="networks-as-containers-of-addresses">
<h4>21.28.3.3.3. Networks as containers of addresses<a class="headerlink" href="#networks-as-containers-of-addresses" title="Permalink to this headline">¶</a></h4>
<p>Network objects can act as containers of addresses.  Some examples:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/28&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">IPv4Address(&#39;192.0.2.0&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/28&#39;</span><span class="p">)[</span><span class="mi">15</span><span class="p">]</span>
<span class="go">IPv4Address(&#39;192.0.2.15&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.0.2.6&#39;</span><span class="p">)</span> <span class="ow">in</span> <span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/28&#39;</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.0.3.6&#39;</span><span class="p">)</span> <span class="ow">in</span> <span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/28&#39;</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="interface-objects">
<h2>21.28.4. Interface objects<a class="headerlink" href="#interface-objects" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="ipaddress.IPv4Interface">
<em class="property">class </em><tt class="descclassname">ipaddress.</tt><tt class="descname">IPv4Interface</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.IPv4Interface" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an IPv4 interface.  The meaning of <em>address</em> is as in the
constructor of <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a>, except that arbitrary host addresses
are always accepted.</p>
<p><a class="reference internal" href="#ipaddress.IPv4Interface" title="ipaddress.IPv4Interface"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Interface</span></tt></a> is a subclass of <a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a>, so it inherits
all the attributes from that class.  In addition, the following attributes
are available:</p>
<dl class="attribute">
<dt id="ipaddress.IPv4Interface.ip">
<tt class="descname">ip</tt><a class="headerlink" href="#ipaddress.IPv4Interface.ip" title="Permalink to this definition">¶</a></dt>
<dd><p>The address (<a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a>) without network information.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span> <span class="o">=</span> <span class="n">IPv4Interface</span><span class="p">(</span><span class="s">&#39;192.0.2.5/24&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span><span class="o">.</span><span class="n">ip</span>
<span class="go">IPv4Address(&#39;192.0.2.5&#39;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Interface.network">
<tt class="descname">network</tt><a class="headerlink" href="#ipaddress.IPv4Interface.network" title="Permalink to this definition">¶</a></dt>
<dd><p>The network (<a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a>) this interface belongs to.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span> <span class="o">=</span> <span class="n">IPv4Interface</span><span class="p">(</span><span class="s">&#39;192.0.2.5/24&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span><span class="o">.</span><span class="n">network</span>
<span class="go">IPv4Network(&#39;192.0.2.0/24&#39;)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Interface.with_prefixlen">
<tt class="descname">with_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv4Interface.with_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd><p>A string representation of the interface with the mask in prefix notation.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span> <span class="o">=</span> <span class="n">IPv4Interface</span><span class="p">(</span><span class="s">&#39;192.0.2.5/24&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span><span class="o">.</span><span class="n">with_prefixlen</span>
<span class="go">&#39;192.0.2.5/24&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Interface.with_netmask">
<tt class="descname">with_netmask</tt><a class="headerlink" href="#ipaddress.IPv4Interface.with_netmask" title="Permalink to this definition">¶</a></dt>
<dd><p>A string representation of the interface with the network as a net mask.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span> <span class="o">=</span> <span class="n">IPv4Interface</span><span class="p">(</span><span class="s">&#39;192.0.2.5/24&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span><span class="o">.</span><span class="n">with_netmask</span>
<span class="go">&#39;192.0.2.5/255.255.255.0&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv4Interface.with_hostmask">
<tt class="descname">with_hostmask</tt><a class="headerlink" href="#ipaddress.IPv4Interface.with_hostmask" title="Permalink to this definition">¶</a></dt>
<dd><p>A string representation of the interface with the network as a host mask.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span> <span class="o">=</span> <span class="n">IPv4Interface</span><span class="p">(</span><span class="s">&#39;192.0.2.5/24&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">interface</span><span class="o">.</span><span class="n">with_hostmask</span>
<span class="go">&#39;192.0.2.5/0.0.0.255&#39;</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="ipaddress.IPv6Interface">
<em class="property">class </em><tt class="descclassname">ipaddress.</tt><tt class="descname">IPv6Interface</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.IPv6Interface" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct an IPv6 interface.  The meaning of <em>address</em> is as in the
constructor of <a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a>, except that arbitrary host addresses
are always accepted.</p>
<p><a class="reference internal" href="#ipaddress.IPv6Interface" title="ipaddress.IPv6Interface"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Interface</span></tt></a> is a subclass of <a class="reference internal" href="#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Address</span></tt></a>, so it inherits
all the attributes from that class.  In addition, the following attributes
are available:</p>
<dl class="attribute">
<dt id="ipaddress.IPv6Interface.ip">
<tt class="descname">ip</tt><a class="headerlink" href="#ipaddress.IPv6Interface.ip" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Interface.network">
<tt class="descname">network</tt><a class="headerlink" href="#ipaddress.IPv6Interface.network" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Interface.with_prefixlen">
<tt class="descname">with_prefixlen</tt><a class="headerlink" href="#ipaddress.IPv6Interface.with_prefixlen" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Interface.with_netmask">
<tt class="descname">with_netmask</tt><a class="headerlink" href="#ipaddress.IPv6Interface.with_netmask" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="ipaddress.IPv6Interface.with_hostmask">
<tt class="descname">with_hostmask</tt><a class="headerlink" href="#ipaddress.IPv6Interface.with_hostmask" title="Permalink to this definition">¶</a></dt>
<dd><p>Refer to the corresponding attribute documentation in
<a class="reference internal" href="#ipaddress.IPv4Interface" title="ipaddress.IPv4Interface"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Interface</span></tt></a>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="other-module-level-functions">
<h2>21.28.5. Other Module Level Functions<a class="headerlink" href="#other-module-level-functions" title="Permalink to this headline">¶</a></h2>
<p>The module also provides the following module level functions:</p>
<dl class="function">
<dt id="ipaddress.v4_int_to_packed">
<tt class="descclassname">ipaddress.</tt><tt class="descname">v4_int_to_packed</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.v4_int_to_packed" title="Permalink to this definition">¶</a></dt>
<dd><p>Represent an address as 4 packed bytes in network (big-endian) order.
<em>address</em> is an integer representation of an IPv4 IP address.  A
<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised if the integer is negative or too large to be an
IPv4 IP address.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">ip_address</span><span class="p">(</span><span class="mi">3221225985</span><span class="p">)</span>
<span class="go">IPv4Address(&#39;192.0.2.1&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">v4_int_to_packed</span><span class="p">(</span><span class="mi">3221225985</span><span class="p">)</span>
<span class="go">b&#39;\xc0\x00\x02\x01&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="ipaddress.v6_int_to_packed">
<tt class="descclassname">ipaddress.</tt><tt class="descname">v6_int_to_packed</tt><big>(</big><em>address</em><big>)</big><a class="headerlink" href="#ipaddress.v6_int_to_packed" title="Permalink to this definition">¶</a></dt>
<dd><p>Represent an address as 16 packed bytes in network (big-endian) order.
<em>address</em> is an integer representation of an IPv6 IP address.  A
<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised if the integer is negative or too large to be an
IPv6 IP address.</p>
</dd></dl>

<dl class="function">
<dt id="ipaddress.summarize_address_range">
<tt class="descclassname">ipaddress.</tt><tt class="descname">summarize_address_range</tt><big>(</big><em>first</em>, <em>last</em><big>)</big><a class="headerlink" href="#ipaddress.summarize_address_range" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator of the summarized network range given the first and last
IP addresses.  <em>first</em> is the first <a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a> or
<a class="reference internal" href="#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Address</span></tt></a> in the range and <em>last</em> is the last <a class="reference internal" href="#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Address</span></tt></a>
or <a class="reference internal" href="#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Address</span></tt></a> in the range.  A <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a> is raised if
<em>first</em> or <em>last</em> are not IP addresses or are not of the same version.  A
<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised if <em>last</em> is not greater than <em>first</em> or if
<em>first</em> address version is not 4 or 6.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">ipaddr</span> <span class="k">for</span> <span class="n">ipaddr</span> <span class="ow">in</span> <span class="n">ipaddress</span><span class="o">.</span><span class="n">summarize_address_range</span><span class="p">(</span>
<span class="gp">... </span>   <span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.0.2.0&#39;</span><span class="p">),</span>
<span class="gp">... </span>   <span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.0.2.130&#39;</span><span class="p">))]</span>
<span class="go">[IPv4Network(&#39;192.0.2.0/25&#39;), IPv4Network(&#39;192.0.2.128/31&#39;), IPv4Network(&#39;192.0.2.130/32&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="ipaddress.collapse_addresses">
<tt class="descclassname">ipaddress.</tt><tt class="descname">collapse_addresses</tt><big>(</big><em>addresses</em><big>)</big><a class="headerlink" href="#ipaddress.collapse_addresses" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an iterator of the collapsed <a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a> or
<a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a> objects.  <em>addresses</em> is an iterator of
<a class="reference internal" href="#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv4Network</span></tt></a> or <a class="reference internal" href="#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><tt class="xref py py-class docutils literal"><span class="pre">IPv6Network</span></tt></a> objects.  A <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a> is
raised if <em>addresses</em> contains mixed version objects.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">ipaddr</span> <span class="k">for</span> <span class="n">ipaddr</span> <span class="ow">in</span>
<span class="gp">... </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">collapse_addresses</span><span class="p">([</span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/25&#39;</span><span class="p">),</span>
<span class="gp">... </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.128/25&#39;</span><span class="p">)])]</span>
<span class="go">[IPv4Network(&#39;192.0.2.0/24&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="ipaddress.get_mixed_type_key">
<tt class="descclassname">ipaddress.</tt><tt class="descname">get_mixed_type_key</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#ipaddress.get_mixed_type_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a key suitable for sorting between networks and addresses.  Address
and Network objects are not sortable by default; they&#8217;re fundamentally
different, so the expression:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">IPv4Address</span><span class="p">(</span><span class="s">&#39;192.0.2.0&#39;</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">IPv4Network</span><span class="p">(</span><span class="s">&#39;192.0.2.0/24&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>doesn&#8217;t make sense.  There are some times however, where you may wish to
have <a class="reference internal" href="#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><tt class="xref py py-mod docutils literal"><span class="pre">ipaddress</span></tt></a> sort these anyway.  If you need to do this, you can use
this function as the <tt class="docutils literal"><span class="pre">key</span></tt> argument to <a class="reference internal" href="functions.html#sorted" title="sorted"><tt class="xref py py-func docutils literal"><span class="pre">sorted()</span></tt></a>.</p>
<p><em>obj</em> is either a network or address object.</p>
</dd></dl>

</div>
<div class="section" id="custom-exceptions">
<h2>21.28.6. Custom Exceptions<a class="headerlink" href="#custom-exceptions" title="Permalink to this headline">¶</a></h2>
<p>To support more specific error reporting from class constructors, the
module defines the following exceptions:</p>
<dl class="exception">
<dt id="ipaddress.AddressValueError">
<em class="property">exception </em><tt class="descclassname">ipaddress.</tt><tt class="descname">AddressValueError</tt><big>(</big><em>ValueError</em><big>)</big><a class="headerlink" href="#ipaddress.AddressValueError" title="Permalink to this definition">¶</a></dt>
<dd><p>Any value error related to the address.</p>
</dd></dl>

<dl class="exception">
<dt id="ipaddress.NetmaskValueError">
<em class="property">exception </em><tt class="descclassname">ipaddress.</tt><tt class="descname">NetmaskValueError</tt><big>(</big><em>ValueError</em><big>)</big><a class="headerlink" href="#ipaddress.NetmaskValueError" title="Permalink to this definition">¶</a></dt>
<dd><p>Any value error related to the netmask.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">21.28. <tt class="docutils literal"><span class="pre">ipaddress</span></tt> &#8212; IPv4/IPv6 manipulation library</a><ul>
<li><a class="reference internal" href="#convenience-factory-functions">21.28.1. Convenience factory functions</a></li>
<li><a class="reference internal" href="#ip-addresses">21.28.2. IP Addresses</a><ul>
<li><a class="reference internal" href="#address-objects">21.28.2.1. Address objects</a></li>
<li><a class="reference internal" href="#conversion-to-strings-and-integers">21.28.2.2. Conversion to Strings and Integers</a></li>
<li><a class="reference internal" href="#operators">21.28.2.3. Operators</a><ul>
<li><a class="reference internal" href="#comparison-operators">21.28.2.3.1. Comparison operators</a></li>
<li><a class="reference internal" href="#arithmetic-operators">21.28.2.3.2. Arithmetic operators</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#ip-network-definitions">21.28.3. IP Network definitions</a><ul>
<li><a class="reference internal" href="#prefix-net-mask-and-host-mask">21.28.3.1. Prefix, net mask and host mask</a></li>
<li><a class="reference internal" href="#network-objects">21.28.3.2. Network objects</a></li>
<li><a class="reference internal" href="#id1">21.28.3.3. Operators</a><ul>
<li><a class="reference internal" href="#logical-operators">21.28.3.3.1. Logical operators</a></li>
<li><a class="reference internal" href="#iteration">21.28.3.3.2. Iteration</a></li>
<li><a class="reference internal" href="#networks-as-containers-of-addresses">21.28.3.3.3. Networks as containers of addresses</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#interface-objects">21.28.4. Interface objects</a></li>
<li><a class="reference internal" href="#other-module-level-functions">21.28.5. Other Module Level Functions</a></li>
<li><a class="reference internal" href="#custom-exceptions">21.28.6. Custom Exceptions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="xmlrpc.server.html"
                        title="previous chapter">21.27. <tt class="docutils literal"><span class="pre">xmlrpc.server</span></tt> &#8212; Basic XML-RPC servers</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="mm.html"
                        title="next chapter">22. Multimedia Services</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/ipaddress.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="mm.html" title="22. Multimedia Services"
             >next</a> |</li>
        <li class="right" >
          <a href="xmlrpc.server.html" title="21.27. xmlrpc.server — Basic XML-RPC servers"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="internet.html" >21. Internet Protocols and Support</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2015, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Aug 30, 2015.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
    </div>

  </body>
</html>